package com.twu.biblioteca.Models;

/**
 * Wrapper for username and password and the methods to manipulate them
 * @author Nimrod Wandera
 */
public class LogInDetails {

    private int username;
    private String password;

    public LogInDetails(int username, String password) {
        this.username = username;
        this.password = password;
    }

    public int getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getLibraryNumber() {
        String usernameString = Integer.toString(username);
        assert usernameString.length() == 7;
        return usernameString.substring(0, 3) + "-" + usernameString.substring(3);
    }

    /**
     * @return a username if <code>username</code> is well formatted. Else -1
     */
    public static int parseStringAsUsername(String username) {
        if (username.length() == 8 && username.contains("-")) {
            String[] usernameParts = username.split("-");
            String cleanedUsernameString = usernameParts[0].trim() + usernameParts[1].trim();
            return Integer.parseInt(cleanedUsernameString);
        }
        else
            return -1;
    }
}
